--
-- Author: mm
-- Date: 2018-08-14 15:29:56
--
-- NewerbattleguideRoleRender
-- 新手战选角-角色节点Render

local ClassRef = app.mvc.createRenderClass(...)

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.newerBattleGuideRoleNode, false, false))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)
    self:setContentSize( self._ui.role:getContentSize() )

    self._ui.role:setSwallowTouches( false )
    display.uiAddClick( self._ui.role, function() -- 选中角色响应
        if self._onClick then
            executeFunc( self._onClick )
        end
    end, true, 0.02)

    self:refresh()
end

-- data = xxxConf
function ClassRef:refresh()
    if self._data then
        local data = self._data
        self:setVisible( true )
        -- 职业背景图片
        self._ui.Image:loadTexture( Res.newerBattleGuideClassRoleBg .. Res.newerBattleGuideClassIconName[ tonumber( self._data:getClassID() ) ], 0 )
    else
        self:setVisible( false )
    end
end

-- 粒子特效播放函数
function ClassRef:setParticlePlay( b )
    b = b or false
    if b then
        self._ui.Particle:setVisible( true )
        self._ui.Particle:resetSystem()
    else
        self._ui.Particle:setVisible( false )
        self._ui.Particle:stopSystem()
    end
end

-- 设置点击响应性
function ClassRef:setCanBeTouch( b )
    b = b or false
    self._ui.role:setTouchEnabled( b )
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
